﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Listing.cs" company="XamlmNinja">
//   2010
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace Communications.PropertySearch.Resources
{
    using System;
    using System.Xml.Serialization;
    using Newtonsoft.Json;

    [JsonObject(MemberSerialization.OptIn)]
    [XmlTypeAttribute(TypeName = "listing")]
    public sealed class Listing
    {
        public Listing()
        {
        }

        [JsonProperty("auction_date")]
        [XmlAttribute(AttributeName = "auction_date", Type = typeof(string))]
        public string AuctionDate { get; set; }

        [JsonProperty("bathroom_number")]
        [JsonConverter(typeof(EmptyStringToNullableIntConverter))]
        [XmlIgnore]
        public int? BathroomCount { get; set; }

        [JsonIgnore]
        [XmlAttribute(AttributeName = "bathroom_number", Type = typeof(string))]
        public string BathroomCountAsString
        {
            get { return BathroomCount.ToString(); }
            set { BathroomCount = !string.IsNullOrEmpty(value) ? (int?) Convert.ToInt32(value) : null; }
        }

        [JsonProperty("bedroom_number")]
        [JsonConverter(typeof(EmptyStringToNullableIntConverter))]
        [XmlIgnore]
        public int? BedroomCount { get; set; }
     
        [JsonIgnore]
        [XmlAttribute(AttributeName = "bedroom_number", Type = typeof(string))]
        public string BedroomCountAsString
        {
            get { return BedroomCount.ToString(); }
            set { BedroomCount = !string.IsNullOrEmpty(value) ? (int?)Convert.ToInt32(value) : null; }
        }

        [JsonProperty("car_spaces")]
        [XmlIgnore]
        public int? CarSpaces { get; set; }
       
        [JsonIgnore]
        [XmlAttribute(AttributeName = "car_spaces", Type = typeof(string))]
        public string CarSpacesAsString
        {
            get { return CarSpaces.ToString(); }
            set { CarSpaces = !string.IsNullOrEmpty(value) ? (int?)Convert.ToInt32(value) : null; }
        }

        [JsonProperty("commission")]
        [XmlAttribute(AttributeName = "commission", Type = typeof(string))]
        public string Commission { get; set; }

        [JsonProperty("construction_year")]
        [XmlIgnore]
        public int? ConstructionYear { get; set; }
       
        [JsonIgnore]
        [XmlAttribute(AttributeName = "construction_year", Type = typeof(string))]
        public string ConstructionYearAsString
        {
            get { return ConstructionYear.ToString(); }
            set { ConstructionYear = !string.IsNullOrEmpty(value) ? (int?)Convert.ToInt32(value) : null; }
        }

        [JsonProperty("datasource_name")]
        [XmlAttribute(AttributeName = "datasource_name", Type = typeof(string))]
        public string DatasourceName { get; set; }

        [JsonProperty("guid")]
        [XmlAttribute(AttributeName = "guid", Type = typeof(string))]
        public string Guid { get; set; }

        [JsonProperty("price_high")]
        [XmlAttribute(AttributeName = "price_high", Type = typeof(decimal))]
        public decimal GuidePriceMax { get; set; }

        [JsonProperty("price_low")]
        [XmlAttribute(AttributeName = "price_low", Type = typeof(decimal))]
        public decimal GuidePriceMin { get; set; }

        [JsonProperty("img_height")]
        [XmlAttribute(AttributeName = "img_height", Type = typeof(int))]
        public int ImageHeight { get; set; }

        [JsonProperty("img_url")]
        [XmlAttribute(AttributeName = "img_url", Type = typeof(string))]
        public string ImageUrl { get; set; }

        [JsonProperty("img_width")]
        [XmlAttribute(AttributeName = "img_width", Type = typeof(int))]
        public int ImageWidth { get; set; }

        [JsonProperty("keywords")]
        [XmlAttribute(AttributeName = "keywords", Type = typeof(string))]
        public string Keywords { get; set; }

        [JsonProperty("land_size")]
        [XmlAttribute(AttributeName = "land_size", Type = typeof(decimal?))]
        public decimal? LandSize { get; set; }

        [JsonProperty("land_size_unit")]
        [XmlAttribute(AttributeName = "land_size_unit", Type = typeof(string))]
        public string LandSizeUom { get; set; }

        [JsonProperty("latitude")]
        [XmlAttribute(AttributeName = "latitude", Type = typeof(string))]
        public string LatitudeAsString
        {
            get { return Latitude.ToString(); }
            set { Latitude = decimal.Parse(value); }
        }

        [JsonIgnore]
        [XmlIgnore]
        public decimal Latitude { get; set; }

        [JsonProperty("lister_name")]
        [XmlAttribute(AttributeName = "lister_name", Type = typeof(string))]
        public string ListerName { get; set; }

        [JsonProperty("lister_url")]
        [XmlAttribute(AttributeName = "lister_url", Type = typeof(string))]
        public string ListerUrl { get; set; }

        [JsonProperty("listing_type")]
        [XmlAttribute(AttributeName = "listing_type", Type = typeof(string))]
        public string ListingType { get; set; }

        [JsonProperty("location_accuracy")]
        [XmlAttribute(AttributeName = "location_accuracy", Type = typeof(string))]
        public string LocationAccuracy { get; set; }

        [JsonProperty("longitude")]
        [XmlAttribute(AttributeName = "longitude", Type = typeof(string))]
        public string LongitudeAsString
        {
            get { return Longitude.ToString(); }
            set { Longitude = decimal.Parse(value); }
        }

        [JsonIgnore]
        [XmlIgnore]
        public decimal Longitude { get; set; }

        [JsonProperty("price")]
        [XmlAttribute(AttributeName = "price", Type = typeof(decimal))]
        public decimal Price { get; set; }

        [JsonProperty("price_currency")]
        [XmlAttribute(AttributeName = "price_currency", Type = typeof(string))]
        public string PriceCurrency { get; set; }

        [JsonProperty("price_formatted")]
        [XmlAttribute(AttributeName = "price_formatted", Type = typeof(string))]
        public string PriceFormatted { get; set; }

        [JsonProperty("price_type")]
        [XmlAttribute(AttributeName = "price_type", Type = typeof(string))]
        public string PriceType { get; set; }

        [JsonProperty("price_coldrent")]
        [XmlAttribute(AttributeName = "price_coldrent", Type = typeof(decimal))]
        public decimal PriceColdrent { get; set; }

        [JsonProperty("property_type")]
        [XmlAttribute(AttributeName = "property_type", Type = typeof(string))]
        public string PropertyType { get; set; }
       
        [JsonProperty("room_number")]
        [XmlIgnore]
        public int? RoomCount { get; set; }

        [JsonIgnore]
        [XmlAttribute(AttributeName = "room_number", Type = typeof(string))]
        public string RoomCountAsString
        {
            get { return RoomCount.ToString(); }
            set { RoomCount = !string.IsNullOrEmpty(value) ? (int?)Convert.ToInt32(value) : null; }
        }

        [JsonProperty("summary")]
        [XmlAttribute(AttributeName = "summary", Type = typeof(string))]
        public string Summary { get; set; }

        [JsonProperty("thumb_height")]
        [XmlIgnore]
        public int? ThumbHeight { get; set; }

        [JsonIgnore]
        [XmlAttribute(AttributeName = "thumb_height", Type = typeof(string))]
        public string ThumbHeightAsString
        {
            get { return ThumbHeight.ToString(); }
            set { ThumbHeight = !string.IsNullOrEmpty(value) ? (int?)Convert.ToInt32(value) : null; }
        }

        [JsonProperty("thumb_url")]
        [XmlAttribute(AttributeName = "thumb_url", Type = typeof(string))]
        public string ThumbUrl { get; set; }

        [JsonProperty("thumb_width")]
        [XmlIgnore]
        public int? ThumbWidth { get; set; }

        [JsonIgnore]
        [XmlAttribute(AttributeName = "thumb_width", Type = typeof(string))]
        public string ThumbWidthAsString
        {
            get { return ThumbWidth.ToString(); }
            set { ThumbWidth = !string.IsNullOrEmpty(value) ? (int?)Convert.ToInt32(value) : null; }
        }

        [JsonProperty("title"),
        XmlAttribute(AttributeName = "title", Type = typeof(string))]
        public string Title { get; set; }

        [JsonProperty("updated_in_days")]
        [XmlAttribute(AttributeName = "updated_in_days", Type = typeof(double))]
        public double UpdatedInDays { get; set; }

        [JsonProperty("updated_in_days_formatted")]
        [XmlAttribute(AttributeName = "updated_in_days_formatted", Type = typeof(string))]
        public string UpdatedInDaysFormatted { get; set; }
    }
}
